package com.insight.consultoria.pool.sessionfactory;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import br.com.insight.consultoria.entity.Area;
import br.com.insight.consultoria.entity.AreaAtuacao;
import br.com.insight.consultoria.entity.ConheceuInsight;
import br.com.insight.consultoria.entity.ConhecimentoInformatica;
import br.com.insight.consultoria.entity.ConhecimentoLinguaEstrangeira;
import br.com.insight.consultoria.entity.CursoExtraCurricular;
import br.com.insight.consultoria.entity.Empresa;
import br.com.insight.consultoria.entity.ExperienciaProfissional;
import br.com.insight.consultoria.entity.EstadoCivil;
import br.com.insight.consultoria.entity.InformacoesAcademicas;
import br.com.insight.consultoria.entity.IntereceAtuacao;
import br.com.insight.consultoria.entity.NivelAcesso;
import br.com.insight.consultoria.entity.NivelAtuacao;
import br.com.insight.consultoria.entity.Noticia;
import br.com.insight.consultoria.entity.PerguntaSecreta;
import br.com.insight.consultoria.entity.RamoAtividade;
import br.com.insight.consultoria.entity.Tipo;
import br.com.insight.consultoria.entity.TipoEspecifico;
import br.com.insight.consultoria.entity.TipoVaga;
import br.com.insight.consultoria.entity.UnidadeFederativa;
import br.com.insight.consultoria.entity.Usuario;
import br.com.insight.consultoria.entity.UsuarioPadrao;
import br.com.insight.consultoria.entity.UsuarioVaga;
import br.com.insight.consultoria.entity.Vaga;

public class HibernateUtil {
	
	private static SessionFactory sessionFactory;
	
	static{
		
		try{
			
			AnnotationConfiguration configuration = new AnnotationConfiguration();
			configuration.configure("hibernate.cfg.xml");
			
			configuration.addAnnotatedClass(NivelAcesso.class);
			configuration.addAnnotatedClass(RamoAtividade.class);
			configuration.addAnnotatedClass(ExperienciaProfissional.class);
			configuration.addAnnotatedClass(Area.class);
			configuration.addAnnotatedClass(Tipo.class);
			configuration.addAnnotatedClass(TipoEspecifico.class);
			configuration.addAnnotatedClass(CursoExtraCurricular.class);
			configuration.addAnnotatedClass(ConhecimentoLinguaEstrangeira.class);
			configuration.addAnnotatedClass(ConhecimentoInformatica.class);
			configuration.addAnnotatedClass(InformacoesAcademicas.class);
			configuration.addAnnotatedClass(EstadoCivil.class);
			configuration.addAnnotatedClass(UnidadeFederativa.class);
			configuration.addAnnotatedClass(PerguntaSecreta.class);
			configuration.addAnnotatedClass(ConheceuInsight.class);
			configuration.addAnnotatedClass(Usuario.class);
			configuration.addAnnotatedClass(UsuarioPadrao.class);
			configuration.addAnnotatedClass(NivelAtuacao.class);
			configuration.addAnnotatedClass(AreaAtuacao.class);
			configuration.addAnnotatedClass(IntereceAtuacao.class);
			configuration.addAnnotatedClass(TipoVaga.class);
			configuration.addAnnotatedClass(Empresa.class);
			configuration.addAnnotatedClass(Vaga.class);
			configuration.addAnnotatedClass(UsuarioVaga.class);
			configuration.addAnnotatedClass(Noticia.class);
		
			
			sessionFactory=configuration.buildSessionFactory();
			
			SchemaExport export=new SchemaExport(configuration);
			export.create(false, true);
			
		}catch(Throwable ex){
			throw new ExceptionInInitializerError(ex);
		}
		
	}
	
	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	public static void shutdown(){
		sessionFactory.close();
	}
}
